package com.apexedu.portal.controller;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.apexedu.framework.dao.BaseDao;
import com.apexedu.framework.util.DBUtil;
import com.apexedu.framework.util.Pager;
import com.apexedu.framework.util.SeqFactory;
import com.apexedu.framework.util.SysPropertiesUtil;
import com.apexedu.identity.IdConstants;
import com.apexedu.identity.entity.TSysUser;
import com.apexedu.portal.constant.ActionConstant;
import com.apexedu.portal.constant.Constants;
import com.apexedu.portal.entity.Lbnewsattachment;
import com.apexedu.portal.entity.Lbxx;
import com.apexedu.portal.entity.TPwdA;
import com.apexedu.portal.entity.TPwdQ;
import com.apexedu.portal.entity.Tblog;
import com.apexedu.portal.util.DBMUtil;
import com.apexedu.portal.util.LittleTimer;
import com.apexedu.util.StringUtil;
import com.apexedu.util.json.JsonUtil;

import cn.com.sr.sdk.ext.api.mail.coremail.CoreMailUtil;


/**
 * 门户4.0展示界面
 * Created by ly on 2015/4/10.
 */
@Controller
public class MhController extends BaseController {

	@Resource
	private BaseDao baseDao;

	/**
	 * 套用iframe界面
	 *
	 * @param request
	 * @param map
	 * @return
	 */
	@RequestMapping(value = ActionConstant.Mh.RequestMapping_frame, method = RequestMethod.GET)
	public String frame(HttpServletRequest request, ModelMap map) {
		debug("<<{}>> frame start", this.getClass().getSimpleName());
		LittleTimer timer = new LittleTimer();
		try {
			map.put("no", request.getParameter("no")); //选中二级菜单的索引
			map.put("url", request.getParameter("q"));
			return ActionConstant.Mh.Forward_frame;
		} catch (Exception e) {
			error("<<{}>> frame error : {}", this.getClass().getSimpleName(), e);
			throw new RuntimeException(e);
		} finally {
			debug("<<{}>> frame end : {}", this.getClass().getSimpleName(), timer.end());
		}
	}

	/**
	 * 修改密码界面
	 *
	 * @return 修改密码界面
	 */
	@RequestMapping(value = ActionConstant.Mh.RequestMapping_uppwd, method = RequestMethod.GET)
	public String uppwd() {
		debug("<<{}>> uppwd start", this.getClass().getSimpleName());
		LittleTimer timer = new LittleTimer();
		try {
			if (Constants.ProjectInfo.PROJECT_CODE.equals("shd")) {
				return ActionConstant.Mh.Forward_uppwdShd;
			} else if (Constants.ProjectInfo.PROJECT_CODE.equals("shmy")) {
				return ActionConstant.Mh.Forward_uppwdShmy;
			} else if (Constants.ProjectInfo.PROJECT_CODE.equals("sdyz")) {
				return ActionConstant.Mh.Forward_uppwdSdyz;
			}else {
				return ActionConstant.Mh.Forward_uppwd;
			}
		} catch (Exception e) {
			error("<<{}>> uppwd error : {}", this.getClass().getSimpleName(), e);
			throw new RuntimeException(e);
		} finally {
			debug("<<{}>> uppwd end : {}", this.getClass().getSimpleName(), timer.end());
		}
	}

	/**
	 * 设置找回密码问题界面
	 *
	 * @param request
	 * @return 设置找回密码问题界面
	 */
	@RequestMapping(value = ActionConstant.Mh.RequestMapping_pwdFind, method = RequestMethod.GET)
	public String pwdFind(HttpServletRequest request) {
		debug("<<{}>> pwdFind start", this.getClass().getSimpleName());
		LittleTimer timer = new LittleTimer();
		try {
			TSysUser user = (TSysUser) request.getSession().getAttribute(IdConstants.SESSION_USER);
			String userid = user.getUserloginid();
			String sql = "select * from t_pwd_q q where q.state=1";
			if (!"admin".equals(userid)) {
				sql += " and instr(type,(select a.groupid from t_yhzd a inner join t_sys_user b on a.yhlx=b.usertype and userloginid='" + userid + "'))>0";
			}
			sql += " order by orderno,wid desc";
			List<TPwdQ> list = DBUtil.queryAllBeanList(sql, TPwdQ.class);
			request.setAttribute("list", list);

			List<TPwdA> pwdAList = baseDao.findByHql(" from TPwdA where userloginid = ? order by orderno", userid);
			if (!pwdAList.isEmpty()) {
				for (TPwdA pwdA : pwdAList) {
					if (pwdA.getOrderno().intValue() == 1) {
						request.setAttribute("pwdA1", pwdAList.get(0));
					}
					if (pwdA.getOrderno().intValue() == 2) {
						request.setAttribute("pwdA2", pwdAList.get(1));
					}
					if (pwdA.getOrderno().intValue() == 3) {
						request.setAttribute("pwdA3", pwdAList.get(2));
					}
				}
			}
			request.setAttribute("type", "edit");
			return ActionConstant.Mh.Forward_pwdFind;
		} catch (Exception e) {
			error("<<{}>> pwdFind error : {}", this.getClass().getSimpleName(), e);
			throw new RuntimeException(e);
		} finally {
			debug("<<{}>> pwdFind end : {}", this.getClass().getSimpleName(), timer.end());
		}
	}

	/**
	 * 保存设置找回密码问题
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = ActionConstant.Mh.RequestMapping_pwdFindSave, method = RequestMethod.POST)
	@ResponseBody
	public void pwdFindSave(HttpServletRequest request) {
		String data = request.getParameter("data");
		debug("<<{}>> pwdFindSave start , data : ", this.getClass().getSimpleName(), data);
		LittleTimer timer = new LittleTimer();
		try {
			List<TPwdA> list = JsonUtil.getDTOList(data, TPwdA.class);
			TSysUser user = (TSysUser) request.getSession().getAttribute(IdConstants.SESSION_USER);
			for (TPwdA pwdA : list) {
				pwdA.setWid(SeqFactory.getNewSequenceAlone());
				pwdA.setUserloginid(user.getUserloginid());
			}
			DBUtil.executeSQL("delete from t_pwd_a where userloginid=?", user.getUserloginid());
			baseDao.saveAll(list);
		} catch (Exception e) {
			error("<<{}>> pwdFindSave error : {}", this.getClass().getSimpleName(), e);
			throw new RuntimeException(e);
		} finally {
			debug("<<{}>> pwdFindSave end : {}", this.getClass().getSimpleName(), timer.end());
		}
	}

	/**
	 * 找回密码界面
	 *
	 * @param step 步骤
	 * @param request --
	 * @return 找回密码界面
	 */
	@RequestMapping(value = ActionConstant.Mh.RequestMapping_findPwd, method = RequestMethod.GET)
	public String findPwd(@PathVariable(ActionConstant.Mh.Variable_step) String step, HttpServletRequest request) {
		debug("<<{}>> findPwd start", this.getClass().getSimpleName());
		LittleTimer timer = new LittleTimer();
		try {
			if ("uid".equals(step)) { //输入用户名界面
				return ActionConstant.Mh.Forward_userid;
			} else if ("qe".equals(step)) { //回答问题界面
				String userid = (String) request.getSession().getAttribute("userid");
				String sql = "select * from t_pwd_q q where q.state=1";
				if (!"admin".equals(userid)) {
					sql += " and instr(type,(select a.groupid from t_yhzd a inner join t_sys_user b on a.yhlx=b.usertype and userloginid='" + userid + "'))>0";
				}
				sql += " order by orderno,wid desc";
				List<TPwdQ> list = DBUtil.queryAllBeanList(sql, TPwdQ.class);
				request.setAttribute("list", list);
				request.setAttribute("type", "find");
				return ActionConstant.Mh.Forward_pwdFind;
			} else if ("pwd".equals(step)) { //设置密码界面
				request.setAttribute("type", "find");
				return ActionConstant.Mh.Forward_uppwd;
			}
			return null;
		} catch (Exception e) {
			error("<<{}>> findPwd error : {}", this.getClass().getSimpleName(), e);
			throw new RuntimeException(e);
		} finally {
			debug("<<{}>> findPwd end : {}", this.getClass().getSimpleName(), timer.end());
		}
	}

	/**
	 * 校验用户账号是否存在
	 *
	 * @param request --
	 * @return 用户账号是否存在
	 */
	@RequestMapping(value = ActionConstant.Mh.RequestMapping_matchUserid, method = RequestMethod.POST)
	@ResponseBody
	public String matchUserid(HttpServletRequest request) {
		debug("<<{}>> matchUserid start", this.getClass().getSimpleName());
		LittleTimer timer = new LittleTimer();
		try {
			String userid = request.getParameter("userid");
			request.getSession().setAttribute("userid", userid);
			return DBUtil.count(" from t_sys_user where userloginid=? and state=1", userid) > 0 ? "true" : "false";
		} catch (Exception e) {
			error("<<{}>> matchUserid error : {}", this.getClass().getSimpleName(), e);
			throw new RuntimeException(e);
		} finally {
			debug("<<{}>> matchUserid end : {}", this.getClass().getSimpleName(), timer.end());
		}
	}

	/**
	 * 校验密保问题
	 *
	 * @param request --
	 * @return 密保问题是否匹配
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = ActionConstant.Mh.RequestMapping_matchQe, method = RequestMethod.POST)
	@ResponseBody
	public String matchQe(HttpServletRequest request) {
		String data = request.getParameter("data");
		debug("<<{}>> matchQe start , data : ", this.getClass().getSimpleName(), data);
		LittleTimer timer = new LittleTimer();
		try {

			List<TPwdA> list = JsonUtil.getDTOList(data, TPwdA.class);
			String userid = (String) request.getSession().getAttribute("userid");
			//用户设置的密保问题及答案
			List<TPwdA> listA = DBUtil.queryAllBeanList("select * from t_pwd_a where userloginid = ? order by orderno", TPwdA.class, userid);
			if (listA != null && listA.size() > 0) {
				for (TPwdA pwdQa : listA) {
					boolean succ = false;
					for (TPwdA pwdA : list) {
						if ((StringUtil.isNotBlank(pwdA.getQid()) && pwdA.getQid().equals(pwdQa.getQid())) || (StringUtil.isNotBlank(pwdA.getCustom()) && pwdA.getCustom().equals(pwdQa.getCustom()))) {
							if (StringUtil.isNotBlank(pwdA.getAnswer()) && pwdA.getAnswer().equals(pwdQa.getAnswer())) {
								succ = true;
							}
						}
					}
					if (!succ) {
						return "false";
					}
				}
				return "true";
			} else {
				return "none";
			}
		} catch (Exception e) {
			error("<<{}>> matchQe error : {}", this.getClass().getSimpleName(), e);
			throw new RuntimeException(e);
		} finally {
			debug("<<{}>> matchQe end : {}", this.getClass().getSimpleName(), timer.end());
		}
	}

	/**
	 * 修改用户信息界面 （邮箱 手机号）
	 *
	 * @return 修改用户信息界面
	 */
	@RequestMapping(value = ActionConstant.Mh.RequestMapping_upuserinfo, method = RequestMethod.GET)
	public String upuserinfo() {
		debug("<<{}>> uppwd start", this.getClass().getSimpleName());
		LittleTimer timer = new LittleTimer();
		try {
			return ActionConstant.Mh.Forward_upuserinfo;
		} catch (Exception e) {
			error("<<{}>> uppwd error : {}", this.getClass().getSimpleName(), e);
			throw new RuntimeException(e);
		} finally {
			debug("<<{}>> uppwd end : {}", this.getClass().getSimpleName(), timer.end());
		}
	}

	/**
	 * 通知公告列表界面
	 *
	 * @return 通知公告列表界面
	 */
	@RequestMapping(value = ActionConstant.Mh.RequestMapping_list, method = RequestMethod.GET)
	public String list(@PathVariable(ActionConstant.Mh.Variable_db) String db, @PathVariable(ActionConstant.Variable_Id) String id, HttpServletRequest request, ModelMap map) {
		debug("<<{}>> list start", this.getClass().getSimpleName());
		LittleTimer timer = new LittleTimer();
		try {
			map.put("db", db);
			map.put("id", id);
			DBMUtil dbmUtil = new DBMUtil(db);
			String sql = "select t.id as id,t.title as title,t.pubtime as time,";
			if ("shgh".equals(Constants.ProjectInfo.PROJECT_CODE)) { //上海工会
				sql += "nvl(t.sfzx,0) as isnew";
			} else {
				sql += "0  as isnew";
			}
			sql += " from tblog  t where t.category = ? ";
			String title = request.getParameter("title");
			if (StringUtil.isNotBlank(title)) {
				title = java.net.URLDecoder.decode(title, "UTF-8");
				sql += " and t.title like '%" + title.replaceAll("'", "") + "%'";
			} else {
				title = "";
			}
			map.put("title", title);
			sql = "select * from (select id,title,time,rownum as rm,isnew from (" + sql + " order by t.pubtime desc,id desc)) t where 1=1 ";
			String p = request.getParameter("p"); //页码
			p = StringUtil.isBlank(p) ? "1" : p;
			Pager pager = new Pager();
			pager.setEachPageRows(19);
			pager.setCurrentPageno(Integer.parseInt(p));
			pager.setTotalRows(dbmUtil.count("select count(*) from ( " + sql + ")", id));
			//结果集合
			List<Lbxx> list = dbmUtil.queryPageBeanList(sql, pager, Lbxx.class, id);
			map.put("list", list);
			map.put("pager", pager);
			//            String typeTitle = new String(request.getParameter("t").getBytes("iso-8859-1"), "utf8"); //分类标题
			String typeTitle = java.net.URLDecoder.decode(request.getParameter("t"), "UTF-8"); //分类标题
			map.put("typeTitle", typeTitle);
			return ActionConstant.Mh.Forward_list;
		} catch (Exception e) {
			error("<<{}>> list error : {}", this.getClass().getSimpleName(), e);
			throw new RuntimeException(e);
		} finally {
			debug("<<{}>> list end : {}", this.getClass().getSimpleName(), timer.end());
		}
	}

	/**
	 * 通知公告明细界面
	 *
	 * @return 通知公告明细界面
	 */
	@RequestMapping(value = ActionConstant.Mh.RequestMapping_noticeDetail, method = RequestMethod.GET)
	public String noticeDetail(@PathVariable(ActionConstant.Mh.Variable_db) String db, @PathVariable(ActionConstant.Variable_Id) String id, ModelMap map) {
		debug("<<{}>> noticeDetail start", this.getClass().getSimpleName());
		LittleTimer timer = new LittleTimer();
		try {
			DBMUtil dbmUtil = new DBMUtil(db);
			Tblog blog = dbmUtil.queryBean("select b.*, to_char(b.pubtime, 'yyyy-MM-dd') as fbsj," + " (select  bm.NAME from lborganization bm where bm.id=b.fbbm) as bmname" + "  from tblog b where b.id =?", Tblog.class, id);
			//查询所有附件
			List<Lbnewsattachment> attach = dbmUtil.queryAllBeanList("select * from LBNEWSATTACHMENT where tblog_id =?", Lbnewsattachment.class, id);
			blog.setAttach(attach);
			//            String content = blog.getContent().replaceAll("<span[^>]*>", "<span>").replaceAll("<div[^>]*>", "<div>");
			//            blog.setContent(content);
			map.put("blog", blog);
			return ActionConstant.Mh.Forward_noticeDetail;
		} catch (Exception e) {
			error("<<{}>> noticeDetail error : {}", this.getClass().getSimpleName(), e);
			throw new RuntimeException(e);
		} finally {
			debug("<<{}>> noticeDetail end : {}", this.getClass().getSimpleName(), timer.end());
		}
	}

	/**
	 * 通知公告明细界面
	 *
	 * @return 通知公告明细界面
	 */
	@RequestMapping(value = ActionConstant.Mh.RequestMapping_noticeDetail_nologin, method = RequestMethod.GET)
	public String noticeDetailNologin(@PathVariable(ActionConstant.Mh.Variable_db) String db, @PathVariable(ActionConstant.Variable_Id) String id, ModelMap map) {
		debug("<<{}>> noticeDetail start", this.getClass().getSimpleName());
		LittleTimer timer = new LittleTimer();
		try {
			DBMUtil dbmUtil = new DBMUtil(db);
			Tblog blog = dbmUtil.queryBean("select b.*, to_char(b.pubtime, 'yyyy-MM-dd') as fbsj," + " (select  bm.NAME from lborganization bm where bm.id=b.fbbm) as bmname" + "  from tblog b where b.id =?", Tblog.class, id);
			//查询所有附件
			List<Lbnewsattachment> attach = dbmUtil.queryAllBeanList("select * from LBNEWSATTACHMENT where tblog_id =?", Lbnewsattachment.class, id);
			blog.setAttach(attach);
			//            String content = blog.getContent().replaceAll("<span[^>]*>", "<span>").replaceAll("<div[^>]*>", "<div>");
			//            blog.setContent(content);
			map.put("blog", blog);
			return ActionConstant.Mh.Forward_noticeDetail;
		} catch (Exception e) {
			error("<<{}>> noticeDetail error : {}", this.getClass().getSimpleName(), e);
			throw new RuntimeException(e);
		} finally {
			debug("<<{}>> noticeDetail end : {}", this.getClass().getSimpleName(), timer.end());
		}
	}

	/**
	 * 通知公告界面附件下载
	 *
	 * @param id
	 * @param response
	 */
	@RequestMapping(value = ActionConstant.Mh.RequestMapping_download, method = RequestMethod.GET)
	public void download(@PathVariable(ActionConstant.Variable_Id) String id, HttpServletResponse response) {
		debug("<<{}>> download start", this.getClass().getSimpleName());
		LittleTimer timer = new LittleTimer();
		OutputStream os = null;
		BufferedInputStream bis = null;
		HttpURLConnection httpUrl = null;
		try {
			Lbnewsattachment att = new DBMUtil("oa").queryBean("select * from LBNEWSATTACHMENT where id=?", Lbnewsattachment.class, id);
			//建立链接
			URL url = new URL(SysPropertiesUtil.get("tzggUrl") + att.getId() + ".Document");
			httpUrl = (HttpURLConnection) url.openConnection();
			//连接指定的资源
			httpUrl.connect();
			//获取网络输入流
			bis = new BufferedInputStream(httpUrl.getInputStream());
			response.reset();
			response.setContentType("application/msword");
			response.addHeader("Content-Disposition", "attachment;filename=" + new String(att.getDocument().getBytes("gbk"), "iso-8859-1"));
			byte[] b = new byte[2048];
			int len = 0;

			os = new BufferedOutputStream(response.getOutputStream());
			while ((len = bis.read(b)) != -1) {
				os.write(b, 0, len);
			}
		} catch (Exception e) {
			error("<<{}>> download error : {}", this.getClass().getSimpleName(), e);
			throw new RuntimeException(e);
		} finally {
			try {
				if (os != null)
					os.flush();
			} catch (Exception e) {
			}
			try {
				if (os != null)
					os.close();
			} catch (Exception e) {
			}
			try {
				if (bis != null)
					bis.close();
			} catch (Exception e) {
			}
			try {
				if (httpUrl != null)
					httpUrl.disconnect();
			} catch (Exception e) {
			}
			debug("<<{}>> download end : {}", this.getClass().getSimpleName(), timer.end());
		}
	}

	/**
	 * 打开头像修改页面
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = ActionConstant.Mh.RequestMapping_openHeadPortrait, method = { RequestMethod.GET, RequestMethod.POST })
	public String openHeadPortrait(HttpServletRequest request, ModelMap modelMap) {
		debug("<<{}>> openHeadPortrait start", this.getClass().getSimpleName());
		LittleTimer timer = new LittleTimer();
		try {
			TSysUser user = (TSysUser) request.getSession().getAttribute(IdConstants.SESSION_USER);
			if (null == user) {//判断用户是否登录
				return "redirect:/identity/index.action";
			}
			modelMap.put("ERROR", "");
			if (Constants.ProjectInfo.PROJECT_CODE.equals("shd")) {
				return ActionConstant.Mh.Forward_headPortraitShd;
			} else if (Constants.ProjectInfo.PROJECT_CODE.equals("shmy")) {
				return ActionConstant.Mh.Forward_headPortraitShmy;
			} else if (Constants.ProjectInfo.PROJECT_CODE.equals("sdyz")) {
				return ActionConstant.Mh.Forward_headPortraitSdyz;
			} else {
				return ActionConstant.Mh.Forward_headPortrait;
			}
		} catch (Exception e) {
			error("<<{}>> openHeadPortrait error : {}", this.getClass().getSimpleName(), e);
			throw new RuntimeException(e);
		} finally {
			debug("<<{}>> openHeadPortrait end : {}", this.getClass().getSimpleName(), timer.end());
		}
	}

	/**
	 * 上传用户头像
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = ActionConstant.Mh.RequestMapping_updateHeadPortrait, method = { RequestMethod.GET, RequestMethod.POST })
	public String updateHeadPortrait(HttpServletRequest request, @RequestParam MultipartFile files, ModelMap modelMap) {
		debug("<<{}>> updateHeadPortrait start", this.getClass().getSimpleName());
		LittleTimer timer = new LittleTimer();
		FileOutputStream outputStream = null;
		InputStream inputStream = null;
		try {
			TSysUser user = (TSysUser) request.getSession().getAttribute(IdConstants.SESSION_USER);
			if (null == user) {//判断用户是否登录
				return "redirect:/identity/index.action";
			}
			if (files.isEmpty()) {
				modelMap.put("ERROR", "上传文件为空！");
			} else {
				String fileName = files.getOriginalFilename();//原始文件名称
				String fileType = fileName.substring(fileName.lastIndexOf(".")).toLowerCase();
				if (".jpg".equals(fileType) || ".png".equals(fileType) || ".gif".equals(fileType) || ".jpeg".equals(fileType) || ".bmp".equals(fileType)) {//判断是否为jpg格式的图片

					inputStream = files.getInputStream();
					int k = 0;
					byte[] bytes = new byte[1024];
					String path = request.getSession().getServletContext().getRealPath("");//获取项目跟路径
					path = path + File.separator + "userinfo" + File.separator + user.getUserloginid();
					//path = path + fileType;
					File file = new File(path);
					if (file.exists()) {
						file.createNewFile();
					}
					/********** 写入文件 *********/
					outputStream = new FileOutputStream(file);
					while ((k = inputStream.read(bytes)) != -1) {
						outputStream.write(bytes, 0, k);
					}
					return "redirect:/s/" + ActionConstant.Mh.RequestMapping_openHeadPortrait;
				} else {
					modelMap.put("ERROR", "上传图片必须为jpg格式！");
				}
			}
			return ActionConstant.Mh.Forward_headPortrait;
		} catch (Exception e) {
			error("<<{}>> updateHeadPortrait error : {}", this.getClass().getSimpleName(), e);
			throw new RuntimeException(e);
		} finally {
			if (null != outputStream) {
				try {
					outputStream.close();
				} catch (IOException e) {
					error("<<{}>> updateHeadPortrait error : {}", this.getClass().getSimpleName(), e);
					throw new RuntimeException(e);
				}
			}
			if (null != inputStream) {
				try {
					inputStream.close();
				} catch (IOException e) {
					error("<<{}>> updateHeadPortrait error : {}", this.getClass().getSimpleName(), e);
					throw new RuntimeException(e);
				}
			}
			debug("<<{}>> updateHeadPortrait end : {}", this.getClass().getSimpleName(), timer.end());
		}
	}

	/**
	 * 获取页脚信息
	 *
	 *
	 * @return 页脚信息
	 */
	@RequestMapping(value = ActionConstant.Mh.RequestMapping_foot, method = RequestMethod.GET)
	@ResponseBody
	public String foot() {
		debug("<<{}>> foot start", this.getClass().getSimpleName());
		LittleTimer timer = new LittleTimer();
		try {
			return DBUtil.queryField("select content from t_footer where state=1");
		} catch (Exception e) {
			error("<<{}>> foot error : {}", this.getClass().getSimpleName(), e);
			throw new RuntimeException(e);
		} finally {
			debug("<<{}>> foot end : {}", this.getClass().getSimpleName(), timer.end());
		}
	}

	/**
	 * 代办信息在门户呈现
	 * 
	 * @return
	 */
	@RequestMapping(value = "/uc/yw/index", method = RequestMethod.GET)
	public synchronized String index(HttpServletRequest request, ModelMap model, String url) {
		try {
			//TSysUser user = (TSysUser) request.getSession().getAttribute(IdConstants.SESSION_USER);
			request.setAttribute("url", url);
			return "portal/" + Constants.ProjectInfo.PROJECT_CODE + "/index_yw";
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	/**
	 * 跳转到coremail页面
	 *
	 * @return 初始界面
	 */
	@RequestMapping(value = ActionConstant.Mh.RequestMapping_gotomail, method = RequestMethod.GET)
	public String gotoCoremail(HttpServletRequest request, HttpServletResponse response) {
		debug("<<{}>> gotoCoremail start", this.getClass().getSimpleName());
		LittleTimer timer = new LittleTimer();
		TSysUser user = (TSysUser) request.getSession().getAttribute(IdConstants.SESSION_USER);
		try {
			String username = user.getUserloginid();
			CoreMailUtil.backgroundUserLogin(username, request, response);
			return null;
		} catch (Exception e) {
			error("<<{}>> gotoCoremail error : {}", this.getClass().getSimpleName(), e);
			throw new RuntimeException(e);
		} finally {
			debug("<<{}>> gotoCoremail end : {}", this.getClass().getSimpleName(), timer.end());
		}
	}

}
